package com.bee.剑指offer;

import java.util.*;

/**
 * @version 1.0.0
 * @Author yong.Mr
 * @data 2021-05-16
 */
public class 连续子数组的最大和 {

    private static Stack<Integer> stack = new Stack<Integer>();

    private static int max = 0;


    public static int FindGreatestSumOfSubArray(int[] array) {
        if(array.length == 0){
            return 0;
        }
        paiLieAll(array);
        return max;
    }

    public static void paiLieAll(int[] array) {
        if (array.length <= 0) {
            return;
        }
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            int[] temp = new int[array.length - i - 1];
//            System.arraycopy(array, 0, temp, 0, i);
            System.arraycopy(array, i + 1, temp, 0, array.length - i - 1);
            stack.push(array[i]);
            sum += array[i];
            if (max < sum) {
                max = sum;
            }
            paiLieAll(temp);
            stack.pop();
            sum -= array[i];
        }
    }

    public static void main(String[] args) {
        int[] array = new int[]{1,-2,3,10,-4,7,2,-5};
        System.out.println(FindGreatestSumOfSubArray(array));
    }
}
